package com.example.demo.filters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.web.server.ServerWebExchange;

import reactor.core.publisher.Mono;

/**
 * Created on 2019-07-16
 */
public class ResponseLogGatewayFilterFactory extends AbstractGatewayFilterFactory {
    private static final Logger logger = LoggerFactory.getLogger(ResponseLogGatewayFilterFactory.class);

    @Override
    public GatewayFilter apply(Object config) {

        return (exchange, chain) -> chain.filter(exchange).then(Mono.fromRunnable(() -> log(exchange)));
    }

    private void log(ServerWebExchange exchange) {
        logger.debug("==========开始执行filter[打印response日志]==========");
    }


}
